package com.bosssoft.hr.train.j2se.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.Objects;
import java.util.Set;
/**
 * @Classname: User
 * @Description:用户实体类 在数据中用户和角色是多对多关系通过中间表关联，因此用户内部有角色列表
 * @author: zoubinyan
 * @Date: 2023/2/22
 */

@Data//自动生成了set，get
@AllArgsConstructor
@NoArgsConstructor
public class User extends BaseEntity {
    /**
     * 用户所拥有的多个角色，这里采用set不用list是避免role对象重复
     * 当然这个重复判定你hashcode和equal的判断字段
     */
    private Set<Role> roles;
    /**
     * 工号
     */
    private String code;
    /**
     * 密码
     */
    private String password;
    /**
     * 姓名
     */
    private String name;
    /**
     * 头像
     */
    private String profilePicture;
    /**
     * 性别 0为男，1为女
     */
    private byte sex;
    /**
     * 生日
     */
    private Date birthday;
    /**
     * 电话号码
     */
    private String tel;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 其他联系方式
     */
    private String other;
    /**
     * 部门id 关联部门表
     */
    private Long departmentId;
    /**
     * 职位id 关联职位表
     */
    private Long positionId;


    public User(Long id, String code, String name) {
        this.id = id;
        this.code = code;
        this.name = name;
    }

    public User(Long id, String remark, Long tenantId, Long orgId, Long companyId, Long createdBy, String creator, Date createdTime, Long updatedBy, Date updatedTime, String modifier, byte status, Long version, Set<Role> roles, String code, String password, String name, String profilePicture, Date birthday, String tel, String email, String other, Long departmentId, Long positionId) {
        super(id, remark, tenantId, orgId, companyId, createdBy, creator, createdTime, updatedBy, updatedTime, modifier, status, version);
        this.roles = roles;
        this.code = code;
        this.name = name;
        this.password = password;
        this.profilePicture = profilePicture;
        this.birthday = birthday;
        this.tel = tel;
        this.email = email;
        this.other = other;
        this.departmentId = departmentId;
        this.positionId = positionId;
    }

    /**
     * 依据 id code 和 name 来判别唯一
     */
    @Override
    public boolean equals(Object u) {
        if (this == u) {
            return true;
        }
        if (u == null || getClass() != u.getClass()) {
            return false;
        }
        if (!super.equals(u)) {
            return false;
        }
        User user = (User) u;
        return Objects.equals(code, user.code) && Objects.equals(name, user.name) && Objects.equals(id, user.id);
    }

    /**
     * 依据 id code 和 name 来判别唯一
     */
    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), code, name, id);
    }

    @Override
    public String toString() {
        return "User{" +
                "code='" + code + '\'' +
                ", name='" + name + '\'' +
                ", id=" + id +
                '}';
    }
}
